/**
 * Title:       APScriptHandler.java
 * Copyright:   Copyright (c) 1996-2004 The Agent Factory Working Group. All rights reserved.
 * Licence:     This file is free software; you can redistribute it and/or modify
 *              it under the terms of the GNU Lesser General Public License as published by
 *              the Free Software Foundation; either version 2.1, or (at your option)
 *              any later version.
 *
 *              This file is distributed in the hope that it will be useful,
 *              but WITHOUT ANY WARRANTY; without even the implied warranty of
 *              MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *              GNU Lesser General Public License for more details.
 *
 *              You should have received a copy of the GNU Lesser General Public License
 *              along with Agent Factory; see the file COPYING.  If not, write to
 *              the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 *              Boston, MA 02111-1307, USA.
 */

package com.agentfactory.platform.util;


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

/**
 * @author Robert Ross, Universitat Bremen
 */
public class FileIO {
    public static StringBuffer readFile(String filename) throws IOException {
        InputStream inStream = filename.getClass().getResourceAsStream("/" + filename);
        if(inStream == null) {
            throw new IOException("FileIO: Failed to load resource: "+
                    filename);
        }
        
        String line = null;
        StringBuffer buf = new StringBuffer();
        BufferedReader reader = new BufferedReader(new InputStreamReader(inStream));
        while((line = reader.readLine()) != null) {
            buf.append(line).append("\n");
        }
        reader.close();
        return buf;
    }
    
}

